package com.example.dryyzx.dao;

import com.example.dryyzx.entity.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderMapper {
    @Delete({
        "delete from `order`",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Delete({
        "delete from `order`",
        "where customer_id = #{arg0,jdbcType=INTEGER} and food_id = #{arg1,jdbcType=INTEGER}"
    })
    int deleteByCidFid(Integer arg0,Integer arg1);

    @Insert({
        "insert into `order` (id, customer_id, ",
        "food_id, ",
        "enable)",
        "values (#{id,jdbcType=INTEGER}, #{customerId,jdbcType=INTEGER}, ",
        "#{foodId,jdbcType=INTEGER}, ",
        "#{enable,jdbcType=BIT})"
    })
    int insert(Order record);

    @InsertProvider(type=OrderSqlProvider.class, method="insertSelective")
    int insertSelective(Order record);

    @Select({
        "select",
        "id, customer_id, food_id, enable",
        "from `order`",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.INTEGER),
        @Result(column="food_id", property="foodId", jdbcType=JdbcType.INTEGER),
        @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    Order selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, customer_id, food_id, enable",
            "from `order`",
            "where customer_id = #{arg0,jdbcType=INTEGER} and food_id= #{arg1,jdbcType=INTEGER} and enable = 1"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="customer_id", property="customerId", jdbcType=JdbcType.INTEGER),
            @Result(column="food_id", property="foodId", jdbcType=JdbcType.INTEGER),
            @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    Order selectByCidFid(Integer arg0,Integer arg1);

    @UpdateProvider(type=OrderSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Order record);

    @Update({
        "update `order`",
        "set customer_id = #{customerId,jdbcType=INTEGER},",
          "food_id = #{foodId,jdbcType=INTEGER},",
          "enable = #{enable,jdbcType=BIT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Order record);

    @Update({
            "update `order`",
            "set enable = 0",
            "where customer_id = #{customerId,jdbcType=INTEGER}"
    })
    int disableByCustomerId(Integer customerId);

    @Update({
            "update `order`",
            "set enable = 0",
            "where customer_id = #{arg0,jdbcType=INTEGER} and food_id = #{arg1,jdbcType=INTEGER}"
    })
    int disableByCidFid(Integer arg0,Integer arg1);
}